import {get, post, put, deleteRequest} from '/@/utils/http/axios';
import {AUTHORIZATION} from "/@/store/constants";

enum URL {
    // 数据字典接口
    queryList = '/api/system/dataDictionary',
    create = '/api/system/dataDictionary',
    update = '/api/system/dataDictionary',
    // 数据字典详情接口
    details = '/api/system/dataDictionary',
    // 删除数据字典接口
    delete = '/api/system/dataDictionary/delete',

    // 新增数据字典明细接口
    createDictDesc = '/api/system/dataDictionary/createDictDesc',
    // 编辑数据字典明细接口
    updateDictDesc = '/api/system/dataDictionary/updateDictDesc',
    // 删除数据字典明细接口
    deleteDictDesc = '/api/system/dataDictionary/deleteDictDesc',
}

const token =  localStorage.getItem(AUTHORIZATION);

export interface LoginData {
    username: string;
    password: string;
}

const queryListApi = async (params: any) => get<any>({
    url: URL.queryList, params: params, data: {},
    headers: {
        'Authorization': `Bearer ${token}`
    }
});

const detailApi = async (id: number) => get<any>({
    url: URL.details +"/"+ `${id}`,
    params: {},
    data: {},
    headers: {'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json'}
});

const createApi = async (data: any) => post<any>({
    url: URL.create, params: {}, data: data,
    headers: {'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json'}
});
const updateApi = async (data: any) => put<any>({
    url: URL.update,
    data: data,
    headers: {'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json'}
});

const deleteApi = async (params: any) => deleteRequest<any>({
    url: URL.delete,
    params: params,
    headers: {'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json'}
});

const createDictDescApi = async (data: any) => post<any>({
    url: URL.createDictDesc, params: {}, data: data,
    headers: {'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json'}
});
const updateDictDescApi = async (data: any) => put<any>({
    url: URL.updateDictDesc,
    data: data,
    headers: {'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json'}
});

const deleteDictDescApi = async (id: number) => deleteRequest<any>({
    url: URL.deleteDictDesc +"/"+ `${id}`,
    params: {},
    headers: {'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json'}
});

export {
    queryListApi,
    detailApi,
    createApi,
    updateApi,
    deleteApi,
    createDictDescApi,
    updateDictDescApi,
    deleteDictDescApi
};
